<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    
</head>
<body>
  <button onclick="doInterval()">多次定时</button>
  <button onclick="stop2()">停止单次定时</button>
  <script>
      //单次定时
      var t2 = setTimeout('console.log("hello")',3000);

      function stop2(){
        console.log(2);
        clearTimeout(t2);
      }

      var num = 0;
      var t1 = NaN;
      var m = 0;
      function doInterval()
      {
        ++num;
        if(num%2==1)
        {
          start1();
        }
        else
        {
          stop1();
        }
      }
      

      function stop1(){
        if(!isNaN(t1))
        {
          clearInterval(t1);
        }
      }

      function start1(){
        t1 = setInterval("console.log(m);m++;",500);
      }

      //直接写匿名函数
      setInterval(function(){
        console.log('how');
      },100);

      //写函数引用
      function demo(){
        console.log(111);
      }

      setInterval(demo,200);


  </script>
</body>
</html>